"""create products table

Revision ID: e394600e3a87
Revises: 8af636bb96d3
Create Date: 2025-08-14 17:36:31.565969

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'e394600e3a87'
down_revision: Union[str, None] = '8af636bb96d3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('products',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('workflow_id', sa.Integer(), nullable=False, comment='关联的工作流ID'),
    sa.Column('user_id', sa.Integer(), nullable=False, comment='用户ID'),
    sa.Column('product_title', sa.String(length=500), nullable=False, comment='产品标题'),
    sa.Column('product_tags', sa.Text(), nullable=True, comment='产品标签(JSON格式)'),
    sa.Column('product_description', sa.Text(), nullable=True, comment='产品描述'),
    sa.Column('image_url', sa.Text(), nullable=False, comment='产品图片URL'),
    sa.Column('image_width', sa.Integer(), nullable=True, comment='图片宽度'),
    sa.Column('image_height', sa.Integer(), nullable=True, comment='图片高度'),
    sa.Column('cos_url', sa.Text(), nullable=True, comment='腾讯云COS访问URL'),
    sa.Column('cos_key', sa.String(length=500), nullable=True, comment='腾讯云COS对象键'),
    sa.Column('source_type', sa.String(length=50), nullable=False, comment='数据来源类型: flux_variation, detail_page'),
    sa.Column('source_index', sa.Integer(), nullable=True, comment='在原数据中的索引位置'),
    sa.Column('detail_content', sa.Text(), nullable=True, comment='详情页HTML内容'),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False, comment='创建时间'),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False, comment='更新时间'),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['workflow_id'], ['ai_workflows.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_products_id'), 'products', ['id'], unique=False)
    op.create_index(op.f('ix_products_user_id'), 'products', ['user_id'], unique=False)
    op.create_index(op.f('ix_products_workflow_id'), 'products', ['workflow_id'], unique=False)
    op.create_index(op.f('ix_ai_workflows_id'), 'ai_workflows', ['id'], unique=False)
    op.create_index(op.f('ix_ai_workflows_status'), 'ai_workflows', ['status'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_ai_workflows_status'), table_name='ai_workflows')
    op.drop_index(op.f('ix_ai_workflows_id'), table_name='ai_workflows')
    op.drop_index(op.f('ix_products_workflow_id'), table_name='products')
    op.drop_index(op.f('ix_products_user_id'), table_name='products')
    op.drop_index(op.f('ix_products_id'), table_name='products')
    op.drop_table('products')
    # ### end Alembic commands ###
